﻿using UnityEngine;
using System.Collections;
using UnityEditor;

public class CreateUnitData {



    [MenuItem("俄罗斯方块/清空棋盘")]
    public static void Clear()
    {
        GameObject select = Selection.activeObject as GameObject;
        int count = select.transform.childCount;
        for (int i = 0; i < count; i++)
        {
            GameObject.DestroyImmediate(select.transform.GetChild(0).gameObject);
        }
    }
    [MenuItem("俄罗斯方块/测试菜单")]
    public static void Test()
    {
        GameObject select = Selection.activeObject as GameObject;
        Debug.Log(select.name);
    }


    [MenuItem("俄罗斯方块/创建棋盘")]
    public static void Create()
    {
        //Selection.activeObject
        GameObject select = Selection.activeObject as GameObject;
        Board board = select.GetComponent<Board>();
        board.CreateCells();
        if (board != null)
        {
            GameObject cellPrefab = Resources.Load("Cell") as GameObject;

            for (int i = 0; i < board.Width; i++)
            {
                for (int j = 0; j < board.Height; j++)
                {

                    GameObject cell = GameObject.Instantiate(cellPrefab);
                    cell.transform.parent = (Selection.activeObject as GameObject).transform;
                    cell.transform.localPosition = new Vector3(i , j , 0);
                    cell.name = i.ToString() + "_" + j.ToString();
					Cell cellObject = cell.GetComponent<Cell>();

                   
					cellObject.positon.x = i;
					cellObject.positon.y = j;
                    
                    board.AddCell(cellObject);

				

                }
            }
        }
    }
}
